package cn.gailvlun.gll.presentation.chat.adapter

import android.content.Context
import cn.gailvlun.gll.R
import cn.gailvlun.gll.net.Member
import com.github.markzhai.recyclerview.MultiTypeAdapter
import java.util.function.Consumer

val SILENCE_MEMBER_TITLE = 0
val SILENCE_MEMBER_CONTENT = 1

class SilenceMemberAdapter: MultiTypeAdapter {
    constructor(context: Context?) : super(context) {
        addViewTypeToLayoutMap(SILENCE_MEMBER_TITLE, R.layout.item_silence_member_title)
        addViewTypeToLayoutMap(SILENCE_MEMBER_CONTENT, R.layout.item_silence_member_content)
    }

    fun addMemberList(memberList: List<Member>) {
        clear()
        
        var blockedList: MutableList<Member>? = null
        var unBlockedList: MutableList<Member> = ArrayList()

        memberList.forEach {
            if (it.isBlock) {
                if (blockedList == null) {
                    blockedList = ArrayList()
                }
                blockedList?.add(it)
            } else {
                unBlockedList.add(it)
            }
        }

        if (blockedList != null) {
            add("房客（已禁言）", SILENCE_MEMBER_TITLE)
            addAll(blockedList, SILENCE_MEMBER_CONTENT)
        }

        add("房客（未禁言）", SILENCE_MEMBER_TITLE)
        addAll(unBlockedList, SILENCE_MEMBER_CONTENT)
    }
}